/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.network.miscellaneous.instrument.attachment;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;

import javax.swing.JOptionPane;

import twaver.TWaverConst;
import twaver.network.ui.ElementUI;
import twaver.network.ui.IconAttachment;

public class ThermometerAttachment extends IconAttachment {
	
    public ThermometerAttachment(String name, ElementUI ui) {
        super(name, ui, "/demo/network/miscellaneous/instrument/thermometer.png"); 
    }

    public void paint(Graphics2D g2d) {
        super.paint(g2d);
        g2d.setStroke(new BasicStroke(2));
        g2d.setColor(Color.red);

        int basePoint = 27;
        int topPoint = 5;
        Object o = getElementUI().getElement().getClientProperty("temperature");
        if (o != null) {
            int value = ( (Integer) o).intValue();
            g2d.drawLine(getLocation().x + 5,
                         getLocation().y + basePoint,
                         getLocation().x + 5,
                         getLocation().y + 20 - value + topPoint);
        }
    }
    
    public void performAction(int gesture, MouseEvent e) {
    	if(TWaverConst.MOUSE_LEFT_DOUBLE_CLICKED == gesture){
            Object value = getElementUI().getElement().getClientProperty("temperature");
            if (value != null) {
            	JOptionPane.showMessageDialog(this.getElementUI().getNetwork(), 
            			"temperature=" + ( (Integer) value).intValue());
            }
    	}
    }
}